<?php
/**
 * This page handles the creation of new users, using AJAX Quite heavily.
 * Found at /add/user
 * 
 * This page can only be accessed using mod_rewrite.
 */

    require_once('../SiteIncludes.GLOBAL.php');
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	$gVAR['e'] = '404';
	require_once('error_handler.php');
    }
    
    if(isset($_LOGGEDINUSER) === true && $_LOGGEDINUSER !== false) {
	$TemplateEngine->create_content_html($Templater->makeherounit('XP :: Woops!', 'You are already logged in.', '<a class="btn btn-primary btn-large" href="/">Home Page</a>'));
	$TemplateEngine->setHasSidebar(false);
    } else {
	
	/************************************************************************
	 * 
	 *	    Sign Up Page
	 * 
	 ************************************************************************/
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/EMDE.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ajaxConfirmer.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ToolTip.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/NewUser.js"></script>');
	
	/************************************************************
	 * 
	 * Central Content HTML 
	 * 
	 ***********************************************************/
	$form_open = '<div id="signup_form"><iframe id="x_frame_user_add" name="x_frame_user_add" class="hiddenElement" ></iframe><form action="/edjx/adduser/add" method="POST" target="x_frame_user_add" id="useradd_form">';
	$form_username = <<<EOCHECKUNIT
	    <hr /><div class="row-fluid" id="check_container">
		<div class="span2" style="text-align: right;"><h2>&nbsp;Username&nbsp;:</h2></div>
		<div class="span3" style="text-align: left;">
			<input type="text" name="ib_text_nametocheck" id="ib_text_nametocheck" onchange="NewUser.checkUsername();"/>
		</div>
		<div class="span7" style="text-align: left;"><img src="/img/not_ok.png" id="img_username_status" style="width: 24px; height: 24px;" alt="Status" /> <img id="username_check_wait" src="/img/spin.gif" class="hiddenElement" style="width: 24px; height: 24px;" alt="Loading" /><span class="errorStyle hiddenElement" id="err_check_username">Sorry, Username already taken!</span></div>
	    </div>
EOCHECKUNIT;
	$form_email = <<<EOCHECKUNIT
	    <div class="row-fluid" id="check_container">
		<div class="span2" style="text-align: right;"><h2>&nbsp;Email&nbsp;:</h2></div>
		<div class="span3" style="text-align: left;">
			<input type="text" name="ib_text_emailtocheck" id="ib_text_emailtocheck" onchange="NewUser.checkEmail();"/>
		</div>
		<div class="span7" style="text-align: left;"><img src="/img/not_ok.png" id="img_email_status" style="width: 24px; height: 24px;" alt="Status" /> <img id="username_check_wait" src="/img/spin.gif" class="hiddenElement" style="width: 24px; height: 24px;" alt="Loading" /><span class="errorStyle hiddenElement" id="err_check_email">Invalid Email</span></div>
	    </div>
EOCHECKUNIT;
	$form_password = <<<EOCHECKUNIT
	    <div class="row-fluid" id="check_container">
		<div class="span2" style="text-align: right;"><h2>&nbsp;Password&nbsp;:</h2></div>
		<div class="span3" style="text-align: left;">
			<input type="password" name="ib_text_password_password" id="ib_text_password_password" onchange="NewUser.checkPassword();" onkeyup="NewUser.checkPassword();"/><br />
			<input type="password" placeholder="Type password again to confirm" name="ib_text_password_confirm" id="ib_text_password_confirm" onchange="NewUser.checkPassword();" onkeyup="NewUser.checkPassword();"/>
		</div>
		<div class="span7" style="text-align: left;"><img src="/img/not_ok.png" id="img_password_status" style="width: 24px; height: 24px;" alt="Status" /></div>
	    </div>
EOCHECKUNIT;
	$form_submit = <<<EOCHECKUNIT
	    <div class="row-fluid" id="check_container">
		<div class="span2" style="text-align: right;"><h2>&nbsp;&nbsp;</h2></div>
		<div class="span3" style="text-align: center;">
			<input type="submit" name="ib_submitbutton" id="ib_submitbutton" disabled="disabled" /><br />
			<span id="ib_submit_status" class="hiddenElement errorStyle"></span>
		</div>
		<div class="span7" style="text-align: left;">&nbsp;</div>
	    </div><hr />
EOCHECKUNIT;
	$form_close = '</form></div>';
	
	$complete_open = '<div id="form_complete" style="text-align: center" class="hiddenElement">';
	$complete_body = $Templater->makeherounit('Sign up complete', 'You will receive an email shortly, please click the link inside it to confirm your email.', '<a class="btn btn-primary btn-large" href="/">Home</a> &nbsp; <a class="btn btn-primary btn-large" href="/su/login">Login</a>');
	$complete_close = '</div>';
	
	$TemplateEngine->create_content_html($form_open);	    unset($form_open);
	$TemplateEngine->create_content_html($form_username);	    unset($form_username);
	$TemplateEngine->create_content_html($form_email);	    unset($form_email);
	$TemplateEngine->create_content_html($form_password);	    unset($form_password);
	$TemplateEngine->create_content_html($form_submit);	    unset($form_submit);
	$TemplateEngine->create_content_html($form_close);	    unset($form_close);
	
	$TemplateEngine->create_content_html($complete_open);	    unset($complete_open);
	$TemplateEngine->create_content_html($complete_body);	    unset($complete_body);
	$TemplateEngine->create_content_html($complete_close);	    unset($complete_close);
	
	
	/************************************************************
	 * 
	 * Right Hand Side Box HTML 
	 * 
	 ***********************************************************/
	 
    }
    
    
    
    $TemplateEngine->render();
?>
